package net.peelmeagrape.hibernate.sql;

import net.peelmeagrape.hibernate.xmlgen.XmlAttribute;
import net.peelmeagrape.hibernate.xmlgen.XmlElement;
import net.peelmeagrape.hibernate.xmlgen.XmlText;

import static java.lang.annotation.ElementType.*;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;

@Target({METHOD,FIELD,CONSTRUCTOR,TYPE,PACKAGE})
@Retention(RUNTIME)
@XmlElement(name="sql-query", parent="hibernate-mapping")
public @interface SqlQuery
{
    @XmlText String query();

    @XmlAttribute String name();
    @XmlAttribute("flush-mode") FlushMode flushMode() default FlushMode.AUTO;
    @XmlAttribute boolean cacheable() default false;
    @XmlAttribute("cache-region") String cacheRegion() default "";
    @XmlAttribute("fetch-size") int fetchSize() default -1;
    @XmlAttribute int timeout() default -1;
    @XmlAttribute boolean callable() default false;

    SqlQueryElement[] elements() default {};

    public enum FlushMode
    {
        AUTO("auto"),
        NEVER("never"),
        ALWAYS("always");
        private String value;

        FlushMode(String value)
        {
            this.value = value;
        }

        public String toString()
        {
            return value;
        }
    }
}
